//
//  WHStatusViewCell.swift
//  8.31-WH微博
//
//  Created by 吴涵 on 15/9/10.
//  Copyright © 2015年 wuhan. All rights reserved.
//
import UIKit
let WHStatusCellMargin:CGFloat = 12

let WHStatusIconWidth:CGFloat = 35
/// 默认图片的大小
let WHStatusPictureItemWidth: CGFloat = 90
/// 图片间距
let WHStatusPictureItemMargin: CGFloat = 10
/// 每行最大的图片数量
let WHStatusPictureMaxCount: CGFloat = 3
/// 所有配图一起的最大尺寸
let WHStatusPictureMaxWidth = WHStatusPictureItemWidth * WHStatusPictureMaxCount + (WHStatusPictureMaxCount - 1) * WHStatusPictureItemMargin
class WHStatusViewCell: UITableViewCell {
    
    var statusViewModel: WHUserStatusModel?{
        didSet{
        
        topView.statusViewModel = statusViewModel
            contentLabel.text = statusViewModel?.status.text
//            pictrueViewHeightCons?.constant = WHStatusPictureItemWidth * CGFloat(random() % 4)

            pictureView.statusViewModel = statusViewModel
            pictureViewWidthCons?.constant = pictureView.bounds.width
            pictrueViewHeightCons?.constant = pictureView.bounds.height
            pictureViewTopCons?.constant = statusViewModel?.thumbnailURLs?.count == 0 ? 0 : WHStatusCellMargin
//            print(statusViewModel?.thumbnailURLs?.count == 0 ? 0 : WHStatusCellMargin)
        }
    }
    var pictureViewWidthCons: NSLayoutConstraint?
    
    var pictrueViewHeightCons: NSLayoutConstraint?
    
    var pictureViewTopCons: NSLayoutConstraint?
    
    func rowHeight(model: WHUserStatusModel) -> CGFloat {
        
        statusViewModel = model
        
        layoutIfNeeded()
    
        return CGRectGetMaxY(bottomView.frame)
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     func setUpUI(){
        let topSepView = UIView()
        topSepView.backgroundColor = UIColor(white: 0.85, alpha: 1.0)
    
        contentView.addSubview(topSepView)
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(pictureView)
        contentView.addSubview(bottomView)
//        print(contentLabel)
        let w = UIScreen.mainScreen().bounds.width
        /// 最上面的分隔视图
        topSepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: w, height: 10))
        /// 顶部视图
        topView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topSepView, size: CGSize(width: w, height: WHStatusCellMargin + WHStatusIconWidth))
        /// 正文
        contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: WHStatusCellMargin, y: WHStatusCellMargin))

        /// 最下面的选择按钮
        bottomView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: pictureView, size: CGSize(width: w, height: 44), offset: CGPoint(x: -WHStatusCellMargin, y: WHStatusCellMargin))
//bottomView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: contentView, size: nil)
        
    }
    private lazy var topView: WHTopView = WHTopView()
     lazy var contentLabel = UILabel(title: nil, color: UIColor.darkGrayColor(), fontSize: 15, layoutWidth: UIScreen.mainScreen().bounds.width - 2 * WHStatusCellMargin)
     lazy var pictureView: WHStatusPictureView = WHStatusPictureView()

     lazy var bottomView: WHBottomView = WHBottomView()
}











